package com.holystone.splunk.app.model;

import com.holystone.splunk.app.enums.EventEnums;
import com.holystone.splunk.app.mybatis.model.Alert;
import com.holystone.splunk.app.mybatis.model.Event;
import com.holystone.splunk.utils.DateFormatUtils;

import java.util.*;

/**
 * Copyright (c) 2017, HOLYSTONE Technologies, Inc.
 * All right reserved.
 *
 * @author huyan
 * @date 2017/10/23
 * @desc: 事件在前台页面展示的vo类
 */
public class EventVO extends Event{

    // ----------- 页面展示-------------------
    private String eventStateStr; // 事件状态字符串
    private String isSendEmailStr; // 是否发送邮件字符串
    private String threatLevelStr; // 威胁级别字符串
    private String createTimeStr; // 创建事件字符串
    private Integer alertCount; // 告警数量

    private String earliest; // 查询条件：开始时间
    private String latest; // 查询条件：结束时间

    public static EventVO getEventVO(Event event) {
        if (event == null)
            return null;

        EventVO vo = new EventVO();
        vo.setEventId(event.getEventId());
        vo.setEventSort(event.getEventSort());
        vo.setEventType(event.getEventType());
        vo.setEventDesc(event.getEventDesc());
        vo.setEventOwner(event.getEventOwner());
        vo.setEventDeptId(event.getEventDeptId());
        vo.setEventDeptName(event.getEventDeptName());
        vo.setEventState(event.getEventState());
        vo.setThreatLevel(event.getThreatLevel());
        vo.setDeleteFlag(event.getDeleteFlag());
        vo.setIsSendEmail(event.getIsSendEmail());
        vo.setCreateTime(event.getCreateTime());
        vo.setEmailToAddress(event.getEmailToAddress());
        vo.setEmailTitle(event.getEmailTitle());
        vo.setEmailContent(event.getEmailContent());
        vo.setEventStateStr(EventEnums.EventStateEnum.getStateMsg(event.getEventState()));
        vo.setIsSendEmailStr(EventEnums.EmailEnum.getStateMsg(event.getIsSendEmail()));
        vo.setThreatLevelStr(EventEnums.EventLevelEnum.getLevelMsg(event.getThreatLevel()));
        return vo;
    }

    public static List<EventVO> getEventVOs(Collection<Event> events) {
        List<EventVO> voList = new ArrayList<>();
        for (Event event : events) {
            voList.add(getEventVO(event));
        }
        return voList;
    }

    public static Event getEvent(EventVO vo) {
        if (vo == null)
            return null;
        Event event = new Event();
        event.setEventId(vo.getEventId());
        event.setEventSort(vo.getEventSort());
        event.setEventType(vo.getEventType());
        event.setEventDesc(vo.getEventDesc());
        event.setEventOwner(vo.getEventOwner());
        event.setEventDeptId(vo.getEventDeptId());
        event.setEventDeptName(vo.getEventDeptName());
        event.setEventState(vo.getEventState());
        event.setThreatLevel(vo.getThreatLevel());
        event.setDeleteFlag(vo.getDeleteFlag());
        event.setIsSendEmail(vo.getIsSendEmail());
        event.setCreateTime(vo.getCreateTime());
        event.setEmailToAddress(vo.getEmailToAddress());
        event.setEmailTitle(vo.getEmailTitle());
        event.setEmailContent(vo.getEmailContent());
        return event;
    }


    public String getEarliest() {
        return earliest;
    }

    public void setEarliest(String earliest) {
        this.earliest = earliest;
    }

    public String getLatest() {
        return latest;
    }

    public void setLatest(String latest) {
        this.latest = latest;
    }

    public Integer getAlertCount() {
        return alertCount;
    }

    public void setAlertCount(Integer alertCount) {
        this.alertCount = alertCount;
    }

    private Set<Alert> alerts = new HashSet<>();

    public Set<Alert> getAlerts() {
        return alerts;
    }

    public void setAlerts(Set<Alert> alerts) {
        this.alerts = alerts;
    }

    public String getEventStateStr() {
        return EventEnums.EventStateEnum.getStateMsg(getEventState());
    }

    public void setEventStateStr(String eventStateStr) {
        this.eventStateStr = eventStateStr;
    }

    public String getIsSendEmailStr() {
        return EventEnums.EmailEnum.getStateMsg(getIsSendEmail());
    }

    public void setIsSendEmailStr(String isSendEmailStr) {
        this.isSendEmailStr = isSendEmailStr;
    }

    public String getThreatLevelStr() {
        return EventEnums.EventLevelEnum.getLevelMsg(getThreatLevel());
    }

    public void setThreatLevelStr(String threatLevelStr) {
        this.threatLevelStr = threatLevelStr;
    }

    public String getCreateTimeStr() {
        return DateFormatUtils.date2Str(getCreateTime());
    }

    public void setCreateTimeStr(String createTimeStr) {
        this.createTimeStr = createTimeStr;
    }
}
